$(function () {
    $(".not-96k-video-box").addClass('hide');
    //初始化专业搜索条件
    //初始化专业
    $.initSubject({
        element:'material-subject-box',//初始化专业select元素的ID
        context:'material-subject-context',//显示专业/科目名字内容ID
        initData:$('#subjectIds').val(),//初始化显示的专业数据，默认不设置
        removeCallback:function(parentId,subjectIds){//删除回调
            resetSubjectIds()
        },
        confirmCallback:function(parentId,subjectIds){//点击确认回调
            resetSubjectIds()
        }
    });
    /**
     * 重置专业ID串
     */
    function resetSubjectIds() {
        var _subjectIds = $.getAllSubjectIds("material-subject-context");
        $("input[name=subjectIds]").val(_subjectIds);
    }

    $('body').on('click', '#downloadBtn', function () {
        var subjectIds = $("input[name='subjectIds']").val();
        if(subjectIds==null || $.trim(subjectIds)==''){
            icModale(0,'请选择专业');
            return;
        }else{
            subjectIds = subjectIds.substring(0,subjectIds.length-1);
            subjectIds = subjectIds.substring(1,subjectIds.length);
            var arr = subjectIds.split(",");
            if(arr.length < 2){
                icModale(0,'请选择科目');
                return;
            }
        }
        var params = $("#exportForm").serialize();
        window.location = baseloaction + '/admin/course/material/download?' +params;
    }).on('click','#importBtn',function(){
        uploadMaterialTemplate();
    }).on('ifChanged','input[name=materialType]',function (evt) {
        if(evt.target.checked){
            var materialType = $(this).val();
            if(materialType=='LIVE'){
                $("#playType").val('CC');
            }else if(materialType!="ARTICLE"&&materialType!="LIVE"){
                $("#playType").val('96K');
            }
        }
    });

    function uploadMaterialTemplate() {
        //初始化文件上传窗口
        initUpdateFileWin({
            fileType: 'xlsx',//文件类型
            multiple: false,//是否允许上传多个文件
            cut: false, //是否允许剪切（fileType='img'）起效
            paramDirName: 'import',//文件上传的目录
            url: baseloaction + "/admin/course/material/upload",
            callback: 'uploadMaterialCallback'//上传成功后的回调
        });
    }
});

function uploadMaterialCallback() {
    icModale(0, '上传成功');
}